home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume22 / unpackmaps / part01 next >
Encoding:
Text File  |  1991-08-28  |  23.3 KB  |  802 lines

  1. Newsgroups: comp.sources.misc
  2. From: Chris Lewis <clewis@ferret.ocunix.on.ca>
  3. Subject:  v22i069:  unpackmaps - A  secure comp.mail.maps unpacker, Part01/01
  4. Message-ID: <1991Aug28.025400.19255@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 742ddcb89ba56adc0ae0fba0ac7e02be
  6. Date: Wed, 28 Aug 1991 02:54:00 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Chris Lewis <clewis@ferret.ocunix.on.ca>
  10. Posting-number: Volume 22, Issue 69
  11. Archive-name: unpackmaps/part01
  12. Environment: Pathalias, Cnews, UNIX
  13. Supersedes: unpackmaps3.0: Volume 12, Issue 99,103
  14.  
  15.                 Unpackmaps Version 3.2
  16.                 Chris Lewis
  17.                 clewis@ferret.ocunix.on.ca
  18.  
  19. Unpackmaps is a simple and secure map unpacking facility.
  20.  
  21. It will unpack incoming maps from the UUCP map coordination project
  22. in comp.mail.maps and automatically run pathalias to produce the
  23. UUCP routing table that many mailers can use.
  24.  
  25. It is immune to viral/worm/trojan attack because it uses a specialized
  26. awk script to unpack the maps instead of a generalized (and vulnerable)
  27. unshar (often /bin/sh).  It is less vulnerable to attack than uuhosts
  28. is, but doesn't have to resort to setuid root/chroot strangeness.
  29.  
  30. It has provisions for compressing the maps, running pathalias,
  31. maintaining a site database and includes a program for querying the
  32. database for individual sites.  Unpackmaps can also be modified to
  33. generate the pathalias file with subsets of the maps, and works with
  34. maps cross-posted to other groups.
  35.  
  36. Unpackmaps is very similar to uuhosts in basic functionality and theory
  37. of operation, except:
  38.  
  39.     - compression works.
  40.     - pathalias invocation is built in.
  41.     - much less picky in header parsing.
  42.     - it's a lot easier to customize, configure and install.
  43.  
  44.         CNEWS SITES TAKE NOTE!
  45.  
  46. This version has been modified to work with the impending patch to
  47. cnews that puts *relative* file names into the batch files instead of
  48. full paths.  If you intend to upgrade to the new version of cnews,
  49. you MUST upgrade to this version of unpackmaps.
  50.  
  51. #! /bin/sh
  52. # This is a shell archive.  Remove anything before this line, then feed it
  53. # into a shell via "sh file" or similar.  To overwrite existing files,
  54. # type "sh file -c".
  55. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  56. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  57. # Contents:  README unpackmaps uuwhere
  58. # Wrapped by clewis@ecicrl on Mon Aug 26 23:32:43 1991
  59. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  60. echo If this archive is complete, you will see the following message:
  61. echo '          "shar: End of archive 1 (of 1)."'
  62. if test -f 'README' -a "${1}" != "-c" ; then 
  63.   echo shar: Will not clobber existing file \"'README'\"
  64. else
  65.   echo shar: Extracting \"'README'\" \(7313 characters\)
  66.   sed "s/^X//" >'README' <<'END_OF_FILE'
  67. X            UNPACKMAPS V3.2
  68. X              July 13 1991
  69. X              Chris Lewis
  70. X
  71. X    This README, unpackmaps and uuwhere are Copyright 1990 Chris Lewis,
  72. X    All Rights Reserved.
  73. X
  74. X    You can do anything you want with it, provided that this copyright
  75. X    notice remains intact, you don't claim you wrote it yourself, and you 
  76. X    don't make money selling it directly.  You may redistribute this as
  77. X    you wish, but if you modify it, you should clearly indicate in this
  78. X    README file that it has been modified, by whom, and describe what
  79. X    has been changed.  Reasonable copying charges are okay.
  80. X
  81. X    Though I have taken pains to ensure that this program is reasonably 
  82. X    reliable and secure, I cannot make any warrantee as to the reliability 
  83. X    or security of this software when used on any computer.  It is up to
  84. X    the user of this software to determine its suitability for their
  85. X    purposes and take responsibility for its operation.
  86. X
  87. XThis is source for a simple, *secure*, map unpacking facility.
  88. X
  89. XIt is much simpler than uuhosts, has roughly the same functionality,
  90. Xis easier to install, probably faster and more efficient (at least
  91. Xthe versions I've seen w.r.t. compression), and is considerably less 
  92. Xvulnerable to trojan maps than most map unpackers that other people use.
  93. X(It has fewer vulnerabilities than uuhosts)
  94. X
  95. XThe intent is that any UNIX/XENIX/BSD system that can run news will
  96. Xbe able to run this too, so I'm attempting to keep to greatest-common-
  97. Xdenominator except for pathalias and things that I implement myself.
  98. X
  99. XThis release includes:
  100. X
  101. X    - map unpacking
  102. X    - pathalias operation plus hooks for path customization.
  103. X    - a mechanism for viewing map entries for arbitrary sites.
  104. X      ("uuwhere")
  105. X    - automatic map article deletion if desired.
  106. X    - rebuild of where database.
  107. X
  108. XUnpackmaps has been posted to comp.sources.misc several times over
  109. Xthe last three years
  110. X
  111. XRegarding security: as many may remember, there's been a fair bit of
  112. Xdiscussion on security of map unpacking on the net.  Rather than play
  113. Xaround with trying to make a secure *true* unshar, which probably noone would
  114. Xtrust because it would be so big, I simply made a few simplifying assumptions
  115. Xabout the map format and use an awk script to unpack a map article into
  116. Xa map file.  It checks for and refuses to unpack articles which have
  117. Xslashes in their names.  I sent off some mail to Mel asking whether the
  118. Xassumptions I've made about map format are true, but never got any
  119. Xresponse.  I believe that this is *pretty* secure, in that it doesn't
  120. Xhave to be run as root, doesn't use the Bourne shell for unpacking, and 
  121. Xis careful about the file names it creates.  Please let me know if there 
  122. Xare any holes I didn't think of.
  123. X
  124. XGeneral operation:
  125. X    - your news is modified to batch incoming map article file names
  126. X      to a specific batch file (analogous to normal news batching).  
  127. X    - unpackmaps wakes up, usually once per day, and extracts the
  128. X      maps specified (if any) in the batch file into the map directory.
  129. X      Maps are extracted using a secure awk script without resort
  130. X      to setuid root or other wierdnesses.  If you want the uuwhere
  131. X      facility, unpackmaps will extract site->map file correspondences.
  132. X    - If any maps were extracted, pathalias is fired off, and the 
  133. X      resultant file put in the place specified.
  134. X    - If you've specified uuwhere, the where database will be regenerated.
  135. X    - if anything was done, unpackmaps sends you mail telling you
  136. X      what happened.
  137. X
  138. XInstallation:
  139. X    - If you want to compress the stored map files, set the COMPRESS
  140. X      variable to point your compress program.  You should be using
  141. X      compress versions 3 or 4.  A copy will have come with your
  142. X      news software.
  143. X
  144. X    - If you are on a "smallish" machine, where "smallish" means something
  145. X      like a 386 or 68020 with 4 megabytes of main memory or less,
  146. X      I STRONGLY recommend that you build a special version of compress
  147. X      with 12 bit compression instead of 16.  When this is done, compress
  148. X      is considerably smaller (eg: bss of 32K instead of 400K+).  The reason
  149. X      for this is obvious - pathalias is enormous when it's running, and so
  150. X      is a 16 bit compress.  God help you if it starts to swap.
  151. X
  152. X      Advantages:
  153. X        - the whole thing runs considerably faster
  154. X        - much less swap/paging
  155. X        - on our machine, 16 bit compress practically hangs
  156. X          everyone else when run at the same time as pathalias.
  157. X          (4mb 16Mhz 386)
  158. X
  159. X      Disadvantages:
  160. X        - the map directory is 10% (really!  only 10%!) bigger.
  161. X
  162. X      What I did was the following:
  163. X        - go to the source directory for compress
  164. X        - remove the binary if it is there.
  165. X        - say:
  166. X            make compress CFLAGS=-DUSERMEM=0
  167. X        - rename this to something like /usr/bin/compress12
  168. X        - make sure that uuwhere and unpackmaps shell scripts
  169. X          have the same name.  Eg: /usr/bin/compress12
  170. X
  171. X    - edit unpackmaps to set the variables at the beginning of
  172. X      the shell script.  Note especially the batch file name
  173. X      (see below)
  174. X    - make the directory for the map files, owned by news.
  175. X    - put unpackmaps in a suitable place.  Eg: /usr/lib/news
  176. X    - unpackmaps should be run from the userid that owns and runs news.
  177. X    - su to the news userid, and run:
  178. X        unpackmaps -i
  179. X      This will build the initial path file.
  180. X    - insert into your crontab something like:
  181. X        30 3 * * * /bin/su news -c "<path to unpackmaps>/unpackmaps > /dev/null"
  182. X    - insert into your news sys file something like:
  183. X
  184. X        (C-news)
  185. X
  186. X        maps:comp.mail.maps/all:f:/usr/spool/news/out.special/maps
  187. X
  188. X        (B-news)
  189. X
  190. X        maps:world,comp.mail.maps:F:/usr/spool/batch/maps
  191. X
  192. X    - copy uuwhere to an accessible bin directory after modifying
  193. X      the configuration section at the beginning.
  194. X    
  195. Xuuwhere "sitename" will give you the map name and line numbers where
  196. Xthe site is defined (with #N comments).  Adding a -v option will
  197. Xinvoke compress (if necessary) and show you the map entry itself.
  198. XThe uuwhere mechanism *only* works using the "#N" entries, and will
  199. Xnot search for macro reassignments and other namings.  One other drawback
  200. Xis that uuwhere won't display whole map files directly, but that was
  201. Xnever particularly useful anyways.
  202. X
  203. Xunpackmaps -i: will extract all map articles into the map spool area - useful
  204. Xfor the first time you use it.
  205. X
  206. Xunpackmaps -p: runs pathalias even if no map articles were extracted.
  207. X
  208. Xunpackmaps -P: doesn't run pathalias even if map articles were extracted.
  209. X
  210. Xunpackmaps -w: rebuilds uuwhere database even if no map articles were
  211. Xextracted.
  212. X
  213. XIn order to push the paths file into /usr/lib/uucp, I created a file called
  214. Xpaths in /usr/lib/uucp, with 644 permissions, owned by the userid that runs
  215. Xunpackmaps.
  216. X
  217. XThe package will send mail to who you specify indicating which maps were
  218. Xunpacked, and any error returns from pathalias.
  219. X
  220. XThe uuwhere database is built from the maps as they are unpacked.  After
  221. Xinstallation, it may take a while for the where database to be complete.
  222. X(same as for path files themselves too).  I have implemented a binary
  223. Xsearch routine to make uuwhere go faster, but frankly, the sed's fast
  224. Xenough on all but the slowest machine.  The "-w" option permits you
  225. Xto rebuild the where database immediately.
  226. X
  227. XLet me know of any changes you needed to make to get this to work.
  228. XI'm also open to suggestions for new features....
  229. X----------
  230. XChris Lewis, Phone: (613) 832-0541, Domain: clewis@ferret.ocunix.on.ca
  231. XUUCP: ...!cunews!latour!ecicrl!clewis;
  232. END_OF_FILE
  233.   if test 7313 -ne `wc -c <'README'`; then
  234.     echo shar: \"'README'\" unpacked with wrong size!
  235.   fi
  236.   # end of 'README'
  237. fi
  238. if test -f 'unpackmaps' -a "${1}" != "-c" ; then 
  239.   echo shar: Will not clobber existing file \"'unpackmaps'\"
  240. else
  241.   echo shar: Extracting \"'unpackmaps'\" \(9644 characters\)
  242.   sed "s/^X//" >'unpackmaps' <<'END_OF_FILE'
  243. X:
  244. X#    Unpackmaps 3.2 Copyright 1990, 1991 Chris Lewis, All Rights Reserved
  245. Xtrap "rm -f /tmp/unp?$$; exit" 0 1 2 3 15
  246. XIFS="     
  247. X"
  248. Xexport IFS
  249. XPATH=/bin:/usr/bin
  250. Xexport PATH
  251. X
  252. X#    The name of the file that you've caused your news system to
  253. X#    batch the file names of the map articles.
  254. X#Alpha C-news:
  255. X#BATCH=/usr/lib/news/batch/b.maps/togo
  256. X#Modern C-news (must be directory other than /usr/spool/news/out.going)
  257. X#    You'll have to create out.special and maps and chown them to news.
  258. X#BATCH=/usr/spool/news/out.special/maps/togo
  259. X# Eg: B-news
  260. XBATCH=/usr/spool/batch/maps
  261. X#    News spool directory
  262. XNEWSSPOOL=/usr/spool/news
  263. X#    Where you want the maps to go.
  264. X#    I like using /usr/spool/maps, but on our system, /usr/spool/news
  265. X#    is a separate file system, and /usr runs close to the limit...
  266. XMAPDIR=/usr/spool/maps
  267. X#    Person to mail results and error messages to
  268. XNOTIFY=clewis
  269. X#    pathalias binary
  270. XPATHALIAS=/usr/bin/pathalias
  271. X#    where you want the path files to go:
  272. X#    A convenient place is /usr/lib/uucp/paths which is the smail
  273. X#    default.  If you're going to put this in /usr/lib/uucp, I suggest
  274. X#    (rather than make /usr/lib/uucp writeable by everybody), doing
  275. X#    the following:
  276. X#        su root
  277. X#        cd /usr/lib/uucp
  278. X#        touch paths
  279. X#        chown news paths    (or usenet)
  280. X#        chmod 644 paths
  281. XPATHFILE=/usr/lib/uucp/paths
  282. X#    Auxiliary options to pathalias.  Tune to local tastes....
  283. XPATHOPTS="-dwatmath -drobohack -decijmm -dcognos -dyunexus"
  284. X#    If you have a version[s] of your machine's map entry that is different 
  285. X#    from what's published, change this variable to point at it/them.
  286. X#    (Eg: I publish the first entry here, and the second one is local tuning
  287. X#    and hidden connections)
  288. XPATHLOCAL="/u/clewis/maps/path.local /u/clewis/maps/path.private"
  289. X#    If this variable is set to the compress binary, maps will be
  290. X#    compressed.
  291. XCOMPRESS=/usr/local/bin/comp12
  292. X#    1 to strip comments from maps - don't do this if you want to use
  293. X#    uuwhere.  However, this is a great space saver...
  294. XNOCOMMENTS=0
  295. X#    Define to the name of a file where you want the where database
  296. X#    to be kept.  Undef if you don't want uuwhere at all.
  297. XWHEREFILE=$MAPDIR/where.db
  298. X#    Uncomment this if you want the map unpacker to remove the
  299. X#    News articles after the maps have been extracted from them.
  300. X#    DO NOT DO THIS IF YOU FORWARD MAP ARTICLES TO OTHER SITES!
  301. X#    This also relies on your awk returning "exit" codes properly.
  302. X#    Yours may not...
  303. XUNLINK=
  304. X#    There are two specific tunable places after this point.
  305. X#    You probably don't want to do either, but you might want to
  306. X#    look at them.  Search for "Honeyman" to see the first, and "SUBSET"
  307. X#    to see the second.
  308. X
  309. X#    Edit no more....
  310. X
  311. Xumask 022
  312. X
  313. Xif test ! -d $MAPDIR -o ! -w $MAPDIR
  314. Xthen
  315. X    echo "$MAPDIR missing, unwritable or not a directory" >&2
  316. X    exit 1
  317. Xfi
  318. X
  319. Xfor i
  320. Xdo
  321. X    case $i in
  322. X    -p)
  323. X        runpathalias=true
  324. X        ;;
  325. X    -P)
  326. X        nopath=true
  327. X        ;;
  328. X    -i)
  329. X        cd /
  330. X        rm -f $BATCH.work
  331. X        # using find/sort instead of ls just in case there's lots of
  332. X        # articles....
  333. X        find $NEWSSPOOL/comp/mail/maps -type f -print | sort > $BATCH
  334. X        ;;
  335. X    -w)
  336. X        forcewhere=true
  337. X        ;;
  338. X    *)
  339. X        echo "usage: unpackmaps [-i] [-p] [-w]" >&2
  340. X        exit 1
  341. X        ;;
  342. X    esac
  343. Xdone
  344. X
  345. X#    Force pathalias if there isn't a path file yet
  346. Xif test ! -r "$PATHFILE"
  347. Xthen
  348. X    runpathalias=true
  349. Xfi
  350. X
  351. X#    Force pathalias if any of the $PATHLOCAL has been updated
  352. Xif test -n "$PATHLOCAL" -a -r "$PATHFILE"
  353. Xthen
  354. X    for i in $PATHLOCAL
  355. X    do
  356. X    if test -n "`find $i -newer $PATHFILE -print`"
  357. X    then
  358. X        runpathalias=true
  359. X        outofdate="$outofdate $i"
  360. X    fi
  361. X    done
  362. Xfi
  363. X
  364. Xcd $MAPDIR
  365. XWHERETMP=/tmp/WHERE$$
  366. Xrm -f $WHERETMP
  367. X        
  368. Xwhile test -f $BATCH -o -f $BATCH.work
  369. Xdo
  370. X    # There is no window of vulnerability here as long as noone else is
  371. X    # creating $BATCH.work.
  372. X    if test ! -f $BATCH.work
  373. X    then
  374. X    mv $BATCH $BATCH.work
  375. X    fi
  376. X
  377. X    while read i stuff
  378. X    do
  379. X    #    Using stuff to capture remaining junk on line.
  380. X    #    Eg: C-news article sizes.
  381. X
  382. X    if test -z "$i"
  383. X    then
  384. X        break
  385. X    fi
  386. X
  387. X    if test ! -r $i
  388. X    then
  389. X        i=$NEWSPOOL/$i
  390. X    fi
  391. X
  392. X    if test ! -r $i
  393. X    then
  394. X        echo "$i apparently superseded or expired"
  395. X        continue
  396. X    fi
  397. X
  398. X    # This awk script depends on the following map article format:
  399. X    # <don't cares>
  400. X    # cat << 'something' > filename
  401. X    # map body
  402. X    # something
  403. X    # <don't cares>
  404. X    # "something" doesn't have to be enclosed in quotes in the cat line.
  405. X    # This isn't particularly fast - could be dramatically speeded up
  406. X    # if written in C, but I was trying to ensure that this is as simple
  407. X    # and self-evident as possible.
  408. X
  409. X    awk '
  410. X    BEGIN    {
  411. X        where = "'"$WHEREFILE"'"
  412. X        }
  413. X    $1 == "cat" && collecting == 0 {
  414. X        recno = 1
  415. X        endtoken=$3;
  416. X        if (substr(endtoken, 1, 1) == "'"'"'")
  417. X            endtoken=substr(endtoken, 2, length(endtoken)-2);
  418. X        collecting = 1;
  419. X        foundone = 1;
  420. X        name = $5;
  421. X        if (index(name, "/") != 0) {
  422. X            printf("Security violation attempt in %s!\n", "'$i'");
  423. X            exit 1;
  424. X        } else
  425. X            printf("extracting %s from %s\n", name, "'$i'");
  426. X        next;
  427. X        }
  428. X
  429. X        {
  430. X        if (!collecting)
  431. X            next;
  432. X        if ($1 == endtoken) {
  433. X            line = "rm -f " name ".Z"
  434. X            print "" | line
  435. X            collecting = 0;
  436. X            next
  437. X        }
  438. X        if ($1 ~ /^#N/ && where) {
  439. X            for (i = 2; i <= NF; i++) {
  440. X            sname = $i
  441. X            if (p = index(sname, ","))
  442. X                sname = substr(sname, 1, p-1)
  443. X            printf "@%s %s %d\n", sname, name, recno >> \
  444. X                "'$WHERETMP'";
  445. X            }
  446. X        }
  447. X        if ("'$NOCOMMENTS'" == 1 && $0 ~ /#/)
  448. X            print substr($0, 1, index($0, "#")) > name
  449. X        else {
  450. X            print $0 > name
  451. X        }
  452. X        recno++
  453. X        }
  454. X        
  455. X        END {
  456. X        if (collecting) {
  457. X            printf("Non-terminated map in %s\n", "'$i'");
  458. X            exit 1;
  459. X        }
  460. X        if (!foundone) {
  461. X            printf("%s does not contain a properly formed map\n", "'$i'");
  462. X            exit 1;
  463. X        }
  464. X        }' $i
  465. X
  466. X    if test $? = 0 -a -n "$UNLINK"
  467. X    then
  468. X        rm -f $i
  469. X    fi
  470. X
  471. X    done < $BATCH.work
  472. X    rm $BATCH.work
  473. Xdone > /tmp/unpA$$ 2>&1
  474. X
  475. Xif test -s /tmp/unpA$$
  476. Xthen
  477. X    if grep extracting /tmp/unpA$$ > /dev/null 2>&1
  478. X    then
  479. X    runpathalias=true
  480. X    fi
  481. Xfi
  482. X
  483. Xif test -n "$COMPRESS"
  484. Xthen
  485. X    files=`ls ?.* | sed -e '/\.Z$/d'`
  486. X    if test -n "$files"
  487. X    then
  488. X    $COMPRESS -f $files
  489. X    fi
  490. Xfi
  491. X
  492. Xif test ! -f "$PATHALIAS"
  493. Xthen
  494. X    runpathalias=
  495. Xfi
  496. X
  497. X#echo "runpathalias: $runpathalias"
  498. X
  499. Xif test -n "$runpathalias" -a -z "$nopath"
  500. Xthen
  501. X
  502. X    (
  503. X    if test -n "$COMPRESS"
  504. X    then
  505. X    #  SUBSET: It is possible to run pathalias only on a subset of the
  506. X    #  maps, yet still unpacking all of the maps so that you can use
  507. X    #  uuwhere on them.  This is most useful when you have difficulty
  508. X    #  running pathalias on the whole set of maps.  If you want to do
  509. X    #  this, comment out the first $COMPRESS, uncomment the second, and
  510. X    #  change the ?.can.*.Z to the pattern you want.
  511. X    $COMPRESS -dc [ud].*.Z | cat - $PATHLOCAL
  512. X    #$COMPRESS -dc ?.can.*.Z | cat - $PATHLOCAL
  513. X    else
  514. X    cat [ud].* $PATHLOCAL
  515. X    fi |
  516. X
  517. X    $PATHALIAS -f $PATHOPTS |
  518. X
  519. X    # format of the pathalias -f output is
  520. X    # cost    host    route
  521. X    #
  522. X    # format of a 'paths' file for smail is
  523. X    # host    route    first_hop_cost
  524. X    #
  525. X    # move cost field to end of line:
  526. X
  527. X    sed 's/\(.*\)    \(.*\)    \(.*\)/\2    \3    \1/' |
  528. X
  529. X    # convert target domain/host to lower case:
  530. X
  531. X    #lcasep |
  532. X    
  533. X    #  Honeyman:  The maps used to generate wierd domains, but most of them
  534. X    #  appear to have disappeared now.   The following egrep was recommended
  535. X    #  by Peter Honeyman (the author of pathalias) to get rid of them.  If
  536. X    #  you find them, you might want to uncomment the egrep.
  537. X
  538. X    # egrep -v '(\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z])    .*!.*!)|(.\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z])    )' |
  539. X
  540. X    # sort the stream:
  541. X    
  542. X    sort > /tmp/paths ) > /tmp/unpB$$ 2>&1
  543. X
  544. X    if test ! -s /tmp/paths
  545. X    then
  546. X    echo "Pathalias failed no map file created" >> /tmp/unpB$$
  547. X    else
  548. X    cat /tmp/paths > $PATHFILE 2>> /tmp/unpB$$
  549. X    if test $? != 0
  550. X    then
  551. X        echo "Copy to $PATHFILE failed" >> /tmp/unpB$$
  552. X    else
  553. X        rm /tmp/paths
  554. X    fi
  555. X    echo "Map remade" >> /tmp/unpB$$
  556. X    ls -l $PATHFILE >> /tmp/unpB$$
  557. X    fi
  558. X
  559. X    if test -s /tmp/unpB$$
  560. X    then
  561. X    echo "Pathalias output:" >> /tmp/unpA$$
  562. X    cat /tmp/unpB$$ >> /tmp/unpA$$
  563. X    fi
  564. Xfi
  565. X
  566. Xif test -n "$forcewhere"
  567. Xthen
  568. X    list="?.* $PATHLOCAL"
  569. Xelse
  570. X    if test -n "$outofdate"
  571. X    then
  572. X    list="$list $outofdate"
  573. X    fi
  574. Xfi
  575. X
  576. Xif test -n "$list"
  577. Xthen
  578. X    for i in $list
  579. X    do
  580. X    fname=`basename $i .Z`
  581. X    case $i in
  582. X        *.Z)
  583. X        $COMPRESS -dc $i
  584. X        ;;
  585. X        *)
  586. X        cat $i
  587. X        ;;
  588. X    esac |
  589. X    awk '
  590. X    BEGIN {
  591. X        name = "'"$fname"'"
  592. X        }
  593. X    {
  594. X        if ($1 ~ /^#N/) {
  595. X        for (i = 2; i <= NF; i++) {
  596. X            sname = $i
  597. X            if (p = index(sname, ","))
  598. X            sname = substr(sname, 1, p-1)
  599. X            printf "@%s %s %d\n", sname, name, NR >> \
  600. X            "'$WHERETMP'";
  601. X        }
  602. X        }
  603. X        
  604. X    }'
  605. X    done
  606. Xfi
  607. X
  608. Xif test -n "$WHEREFILE" -a -s $WHERETMP
  609. Xthen
  610. X    if test ! -f $WHEREFILE
  611. X    then
  612. X    touch $WHEREFILE
  613. X    fi
  614. X
  615. X    # First awk: throws away WHERE references in $WHEREFILE that
  616. X    #    are now in $WHERETMP
  617. X    # Sort: sort by site name
  618. X    # Second awk: coalesce references to same site/file to one line.
  619. X    awk '
  620. X    BEGIN {
  621. X        mapseen[""] = 1
  622. X    }
  623. X    $1 ~ /^@/ {
  624. X        printf("%s %s %s\n", substr($1, 2), $2, $3);
  625. X        mapseen[$2] = 1
  626. X        next;
  627. X    }
  628. X    {
  629. X        if (mapseen[$2])
  630. X        next
  631. X        printf("%s %s %s\n", $1, $2, $3);
  632. X    }' $WHERETMP $WHEREFILE | 
  633. X    sort -u | 
  634. X    awk '
  635. X    {
  636. X        if (site != $1 || map != $2) {
  637. X        if (site)
  638. X            printf("\n");
  639. X        site = $1
  640. X        map = $2
  641. X        printf("%s %s %s", $1, $2, $3);
  642. X        lastline = ""
  643. X        } else {
  644. X        if ($3 == lastline)
  645. X            next
  646. X        printf(",%s", $3);
  647. X        lastline = $3
  648. X        }
  649. X    }
  650. X    END {
  651. X        printf("\n");
  652. X    }' > /tmp/TMP2
  653. X    
  654. X    if test -s /tmp/TMP2
  655. X    then
  656. X    cat /tmp/TMP2 > $WHEREFILE
  657. X    fi
  658. X    echo "Where database ($WHEREFILE) rebuilt" >> /tmp/unpA$$
  659. Xfi
  660. Xrm -f /tmp/TMP2 $WHERETMP
  661. X
  662. Xif test -s /tmp/unpA$$
  663. Xthen
  664. X    mail $NOTIFY < /tmp/unpA$$
  665. X#    cat /tmp/unpA$$
  666. Xfi
  667. END_OF_FILE
  668.   if test 9644 -ne `wc -c <'unpackmaps'`; then
  669.     echo shar: \"'unpackmaps'\" unpacked with wrong size!
  670.   fi
  671.   chmod +x 'unpackmaps'
  672.   # end of 'unpackmaps'
  673. fi
  674. if test -f 'uuwhere' -a "${1}" != "-c" ; then 
  675.   echo shar: Will not clobber existing file \"'uuwhere'\"
  676. else
  677.   echo shar: Extracting \"'uuwhere'\" \(2154 characters\)
  678.   sed "s/^X//" >'uuwhere' <<'END_OF_FILE'
  679. X:
  680. X#    Uuwhere 3.2 Copyright 1990, 1991 Chris Lewis, All Rights Reserved
  681. XMAPDIR=/usr/spool/maps
  682. XLOCDIRS=/u/clewis/maps
  683. XWHEREFILE=$MAPDIR/where.db
  684. XCOMPRESS=/usr/bin/compress
  685. X#    A pointer to a program that when passed the
  686. X#    arguments "<user>@site" will probe your
  687. X#    routing database and print the path.  Smail 2.5
  688. X#    does this with additional options "-R -A".  You may
  689. X#    have other programs that can probe your paths database
  690. X#    or other routing information.
  691. XSMAIL="/bin/smail -R -A"
  692. X#    Non-null for smart-host implementation similar to smail 2.5.
  693. XSMART=y
  694. X
  695. Xif [ $1 = "-v" ]
  696. Xthen
  697. X    verbose=1
  698. X    shift
  699. Xfi
  700. Xfor i
  701. Xdo
  702. X    echo Searching for $i
  703. X    if [ -n "SMAIL" ]
  704. X    then
  705. X    token="<user>@$i"
  706. X    route=`$SMAIL $token 2> /dev/null`
  707. X    if [ "$route" != "$token" ]
  708. X    then
  709. X        echo "Route to $i: $route"
  710. X        if [ -n "$SMART" ]
  711. X        then
  712. X        smart=`$SMAIL X@smart-host`
  713. X#        echo "smart: $smart"
  714. X        if [ "$smart" = "X@smart-host" ]
  715. X        then
  716. X            echo "  (Not a smart-hosted route)"
  717. X        else
  718. X            smpath=`echo $smart | sed -e 's/!X//'`
  719. X            rpath=`echo $route | sed -e 's/![^!]*!<user>$//'`
  720. X#            echo "paths: $smpath, $rpath"
  721. X            if [ "$rpath" = "$smpath" ]
  722. X            then
  723. X            echo "  (Possibly smart-hosted route)"
  724. X            else
  725. X            echo "  (Not a smart-hosted route)"
  726. X            fi
  727. X        fi
  728. X        fi
  729. X    else
  730. X        echo "No routing to $i"
  731. X    fi
  732. X    fi
  733. X    if [ -n "$verbose" ]
  734. X    then
  735. X    list=`sed -n -e "/^$i[     ]/s/[     ][     ]*/:/gp" \
  736. X        -e "/^$i[     ]/q" $WHEREFILE`
  737. X    for j in $list
  738. X    do
  739. X        eval `echo $j | sed -e 's/\([^:]*\):\([^:]*\):\(.*\)/s=\1 f=\2 l=\3/p'`
  740. X        #echo $s $f $l
  741. X        numlist=`echo $l | sed -e 's/[, ][, ]*/ /g'`
  742. X        for l in $numlist
  743. X        do
  744. X        #echo "Found $s in $f at line $l"
  745. X        cmd=
  746. X        if [ -n "$f" -a -n "$l" ]
  747. X        then
  748. X            dirs="$MAPDIR $LOCDIRS"
  749. X            for d in $dirs
  750. X            do
  751. X            if [ -r $d/$f ]
  752. X            then
  753. X                cmd="cat $d/$f"
  754. X                break
  755. X            elif [ -r $d/$f.Z ]
  756. X            then
  757. X                cmd="$COMPRESS -dc $d/$f.Z"
  758. X                break
  759. X            fi
  760. X            done
  761. X        fi
  762. X        if test -n "$cmd"
  763. X        then
  764. X            echo
  765. X            echo "Found site $s at line $l of $f:"
  766. X            echo
  767. X            $cmd | sed -n -e "$l,/^#N/p"
  768. X        else
  769. X            echo "Can't find file $f"
  770. X        fi
  771. X        done
  772. X    done
  773. X    else
  774. X    grep "^$i" $WHEREFILE
  775. X    fi
  776. Xdone
  777. END_OF_FILE
  778.   if test 2154 -ne `wc -c <'uuwhere'`; then
  779.     echo shar: \"'uuwhere'\" unpacked with wrong size!
  780.   fi
  781.   chmod +x 'uuwhere'
  782.   # end of 'uuwhere'
  783. fi
  784. echo shar: End of archive 1 \(of 1\).
  785. cp /dev/null ark1isdone
  786. MISSING=""
  787. for I in 1 ; do
  788.     if test ! -f ark${I}isdone ; then
  789.     MISSING="${MISSING} ${I}"
  790.     fi
  791. done
  792. if test "${MISSING}" = "" ; then
  793.     echo You have the archive.
  794.     rm -f ark[1-9]isdone
  795. else
  796.     echo You still must unpack the following archives:
  797.     echo "        " ${MISSING}
  798. fi
  799. exit 0
  800.  
  801. exit 0 # Just in case...
  802.